#include "StartPlayOnByPassToOurPlayerBehaviour.h"

extern CEvaluatingPlayerList* ePlayerList;

/**
 *	Rozohranie lopty spoluhracom zo zahravacich modov, pouzite v metode behaveWithBall
 *	Rozohram vhodne postavenemu hracovi
 *
 *	@param ePlayerList zoznam spoluhracov
 *
 *	@return true prihral nejakeku spoluhracovi ak false, prihral len tak na bod Point(40, 0)
 */
bool StartPlayOnByPassToOurPlayerBehaviour::Behave() 
{				
	double fTmpX, fTmpY;
				
	Point myPosition = world->me->pos;
	if(ePlayerList->CalculateNormalPassPosition(myPosition.GetX(), myPosition.GetY(), fTmpX, fTmpY))
	{
		Point passPosition((float)fTmpX, (float)fTmpY);
		DBGN("Prihravka na (%.3lf, %.3lf)", passPosition.GetX(), passPosition.GetY());

		Vector vectFromMeToPassPoint = passPosition - world->me->pos;
		
		float lfDistance = vectFromMeToPassPoint.GetLength();
		float lfPassSpeed = (lfDistance - (float)lfMinPassDistance) / ((float)lfMaxPassDistance - (float)lfMinPassDistance) 
			* (world->params->server->ball_speed_max - 1.4f) +  1.4f;

		GetPassBallToBehaviour()->Behave(passPosition, GetPassBallToBehaviour()->CorrectPassSpeed(lfPassSpeed));
		return true;
	}
	else
	{
		GetPassBallToBehaviour()->Behave(Point(40, 0) , GetPassBallToBehaviour()->CorrectPassSpeed(world->params->server->ball_speed_max));
		return false;
	}
}